
window.onload = function () {
  const id = document.querySelector('.top .id')
  const phone = document.querySelector('.top .phone')
  const top = document.querySelector('.top')
  const total = document.querySelector('.tasks #total p')
  const complete = document.querySelector('.tasks #complete p')
  const mileage = document.querySelector('.tasks #mileage p')
  const information = document.querySelector('#information')
  const taskData = document.querySelector('#task_data')
  const system_settings = document.querySelector('#system_settings')
  const a = document.querySelector('.common_button .a')
  const b = document.querySelector('.common_button .b')
  const arr = [
    { assemble: 18, completed: 16, mileage: 3987 },
    { assemble: 14, completed: 11, mileage: 4000 },
    { assemble: 30, completed: 11, mileage: 114514 }
  ]

  // 随机的司机编号
  id.innerHTML = `司机编号：${Math.floor(Math.random() * (99999999 - 10000000) + 10000000)}`
  // 数组中提取本月任务
  const num = Math.floor(Math.random() * 3)
  total.innerHTML = arr[num].assemble
  complete.innerHTML = arr[num].completed
  mileage.innerHTML = arr[num].mileage
  localStorage.setItem('assignments', JSON.stringify(arr[num]))


  // 点击跳转
  information.addEventListener('touchstart', function () {
    location.href = '车辆信息.html'
  })
  taskData.addEventListener('touchstart', function () {
    location.href = '日历.html'
  })
  system_settings.addEventListener('touchstart', function () {
    location.href = '系统设置.html'
  })


  //登入的手机号 
  const tel = JSON.parse(localStorage.getItem('ledgerUsers'))
  console.log(tel)
  phone.innerHTML = `手机号：${tel[0].tel}`
  

  // 页面跳转
  a.addEventListener('touchstart', function () {
    location.href = '待提货列表.html'
  })

  b.addEventListener('touchstart', function () {
    location.href = 'news&&mission.html'
  })



}